<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
 * Achievements_model class
 *
 * This class abstracts functions for the photo requests
 *
 * @package		Photoggle
 * @subpackage	Models
 * @category	Models
 * @author		Russ
 */
class CompletedAchievements_model extends CI_Model {

	/* Achievement bahavior */
	var $table_name = 'a_achievements_completed';

	function __construct()
	{
		parent::__construct();
	}


	/**
	 * Get completed achievement by id
	 *
	 * @param	string
	 * @return	object
	 */
	function get_completed_by_id($achievement)
	{
		$this->db->where('id', $id);

		$query = $this->db->get($this->completed_table_name);
		if ($query->num_rows() == 1) return $query->row();
		return NULL;
	}

	/**
	 * Check if completed achievement exists
	 *
	 * @param	string
	 * @return	object
	 */
	function completed_achievement_exists($achievementId, $userId)
	{
		$this->db->where('achievement_id', $achievementId);
		$this->db->where('user_id', $userId);

		$query = $this->db->get($this->completed_table_name);
		if ($query->num_rows() == 1) return true;
		return false;
	}
	
	/**
	 * Count the COMPLETED Achievements
	 *
	 * @access	public
	 * @return	array
	 */
	function get_count_completed_achievements($user_id)
	{
		$sql = "
				SELECT
					*
				FROM
					a_achievements_completed
				WHERE
					user_id = " . $user_id . "
				";
		$query = $this->db->query($sql);
		return $query->num_rows();
	}

 }
 ?>